/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.widgetattr.controller
 * FILE    NAME: WidgetAttrDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.api.widgetattr.controller;

import java.math.BigInteger;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
import com.hero.common.web.context.UserContext;
import com.hero.core.constant.SysConstant;
import com.hero.core.entity.ResponseEntity;
import com.jodinfo.outmirror.api.widgetattr.entity.WidgetAttrEntity;
import com.jodinfo.outmirror.api.widgetattr.service.WidgetAttrBizService;



@Controller
@RequestMapping(value = "/WidgetAttrAdmin")
public class WidgetAttrController  {
	
@Resource(name="widgetAttrBizService")
private WidgetAttrBizService widgetAttrBizService;
/**
*  list数据源
* 
* */
@RequestMapping(value = "/List")
@ResponseBody
public String WidgetAttrList(WidgetAttrEntity widgetAttrEntity) {
	if(widgetAttrEntity==null){
		widgetAttrEntity = new WidgetAttrEntity();
		widgetAttrEntity.setPageIndex(SysConstant.DEFAULT_PAGEINDEX);
		widgetAttrEntity.setPageSize(SysConstant.DEFAULT_PAGESIZE);
	}
	widgetAttrEntity.setCurrentUser(UserContext.getUser());
	String str = widgetAttrBizService.queryListForPageWidgetAttr(widgetAttrEntity);
	return str;
}

/**
*  查询所有属性
* 
* */
@RequestMapping(value = "/queryAllWidgetAttrListJson")
@ResponseBody
public String queryAllWidgetAttrListJson(WidgetAttrEntity widgetAttrEntity) {
	String str = widgetAttrBizService.queryAllWidgetAttrByControlId(widgetAttrEntity.getControlId());
	return str;
}
/**
* WidgetAttrEntity List页面
* 
* */
@RequestMapping(value = "/ListPage")
public ModelAndView widgetAttrListPage(WidgetAttrEntity widgetAttrEntity,HttpServletRequest request) {
	
	return new ModelAndView(returnPath("widgetAttrList"));
}
/**
* WidgetAttrEntity详细页 
* 
* */
@RequestMapping(value = "/EditPage")
public ModelAndView widgetAttrEditPage(WidgetAttrEntity widgetAttrEntity) {
	
	return new ModelAndView(returnPath("widgetAttrAdd"));
}
/**
 * 查询WidgetAttrEntity
 * 
 * */
@RequestMapping(value = "/queryByID")
public @ResponseBody String findWidgetAttrData(HttpServletRequest request) {
	String id = request.getParameter("id");
	WidgetAttrEntity widgetAttrEntity =  widgetAttrBizService.queryById(new BigInteger(id));
	return JSON.toJSONString(widgetAttrEntity); 
}

/**
 * 保存或更新WidgetAttr 
 * 
 * */
@RequestMapping(value = "/saveWidgetAttr")
public @ResponseBody String saveWidgetAttrData(@RequestBody WidgetAttrEntity widgetAttrEntity) {
	ResponseEntity rs = null;
	if(widgetAttrEntity!=null){
		widgetAttrEntity.setCurrentUser(UserContext.getUser());
		if(widgetAttrEntity.getId()!=null){
			rs = widgetAttrBizService.updateWidgetAttr(widgetAttrEntity);
		}else{
			rs = widgetAttrBizService.addWidgetAttr(widgetAttrEntity);
		}
	}
	return JSON.toJSONString(rs);
}
/**
 * 导出WidgetAttrEntity
 * @author shensu
 * @date 2015-7-09  下午2:13:28
 * @return
 */
@RequestMapping(value = "/exportWidgetAttrExcel")
public void exportWidgetAttrExcel(WidgetAttrEntity widgetAttrEntity,HttpServletResponse response) {
		widgetAttrBizService.exportWidgetAttr(widgetAttrEntity, response);
}
/**
 * 定义
 * 
 */
private final String MODULE_PATH = "/widgetattr/";

//返回路径
private String returnPath(String jspName) {
	return MODULE_PATH + jspName;
}
}
